<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 示例接口
 */
class Member extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['test2'];

   public function search()
   {
       $cacheTime = 10;
       $username = input("username");
       $user = Db::name("vip_user")->where("username",$username)->cache($cacheTime)->find();
       if(empty($user)){
           return json(["status"=>401,"msg"=>"请输入正确的用户名"]);
       }
       // 查询时间段
       $timeStart = date('Y-m-18 00:00:00',strtotime('-1 month'));
       $timeEnd = date('Y-m-18 00:00:00',time());
       // 用户数据
       $data["user"]["username"] = $user["username"];
       $data["user"]["level"] = $user["level"];
       $data["user"]["money"] = $user["money"];
       // 晋级奖金数据
       $jiangli = Db::name("vip_jiangli")->where("username",$username)->order("level asc")->cache($cacheTime)->select();
       $data["jiangli"]["username"] = $jiangli["username"];
       $data["jiangli"]["level"] = $jiangli["level"];
       $data["jiangli"]["status"] = $jiangli["status"] == 1 ? "已发放" : "未发放";
       // 好运金数据
       $orders = Db::name("vip_orders")->where("username",$username)->where("savetime",">=",$timeStart)->where("","<",$timeEnd)->select();
   }

}
